from flask import Flask
import os
# from .factory import myAppFactory
from .db import init_app as init_app_db
from .auth import init_app as init_app_auth

# myPool = mySQLConnectionPool()

# 配置
host = 'localhost'
user = 'jj'
password = '12345678'
database = 'myFlask'
port = 3306


def create_app(test_config=None):
    '''
    1. app1  实例创建，参数配置（配置文件、数据库文件读取位置）
    2. 配置文件读取
    3. 加载数据库
    
    '''
    app = Flask(__name__, instance_relative_config=True)

    app.config.from_mapping(
        SECRET_KEY='dev',
        HOST = host,
        USER = user,
        PASSWORD = password,
        DATABASE = database,
        PORT = port
    )

    
    '''
    测试pool
    '''
    
    if test_config is None:
        app.config.from_pyfile('config.py', silent=True)
    else:
        app.config.from_mapping(test_config)
        
    init_app_db(app) # 数据库连接池
    init_app_auth(app)

    from .auth import auth_bp
    app.register_blueprint(auth_bp)

    from .user_profile import user_bp
    app.register_blueprint(user_bp)

    @app.route('/')
    def hello():
        return 'hello world'
    @app.route('/index')
    def index():
        return '登陆成功'

    return app
    

